package com.trkj.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojos.YzrMedicine;
import com.trkj.pojos.YzrPharmacy;
import com.trkj.pojos.YzrStorehouse;
import com.trkj.pojos.YzrSupplier;
import com.trkj.service.YzrEntityService;
import com.trkj.vo.Result;
import com.trkj.vo.YzrPharmacyVo;
import com.trkj.vo.YzrStaffVo;
import com.trkj.vo.YzrStorehouseVo;

@Controller
public class YzrEntityController {
	
	@Autowired
	private YzrEntityService yzrEntityTbService;
	
	
	//主界面
	@RequestMapping("/to_index")
	public String toHost(){
		return "yzr_index";
	}
	
	//药房
	@RequestMapping("/to_pharmacy")
	public String toPharmacy(){
		return "yzr_pharmacy";
	}
	
	//供应商
	@RequestMapping("/to_supplier")
	public String toSupplier(){
		return "yzr_supplier";
	}
	
	//仓库
	@RequestMapping("/to_storehouse")
	public String toStorehouse(){
		return "yzr_storehouse";
	}

	//药品
	@RequestMapping("/to_medicine")
	public String toMedicine(){
		return "yzr_medicine";
	}
		
/**********************************************************************************************/
	//查询所有员工
	@RequestMapping("/queryAllStaff")
	public @ResponseBody List<YzrStaffVo> queryAllStaff(){
		return yzrEntityTbService.queryAllStaff();
	}
	
	//查询所有员工
	@RequestMapping("/queryAllStaff2Yzr")
	public @ResponseBody List<YzrStaffVo> queryAllStaff2(){
		return yzrEntityTbService.queryAllStaff2();
	}
	
/******************************************药房****************************************************/

	
	//添加新药房
	@RequestMapping("/add_pharmacy")
	public @ResponseBody Result addPharmacy(YzrPharmacy pharmacy){
		yzrEntityTbService.addPharmacy(pharmacy);
		return new Result(true,"药房添加成功！");
	}
	
	//分页查询所有药房
	@RequestMapping("/queryAllPharmacy")
	public @ResponseBody Map<String, Object> queryAllPharmacy(int page, int rows){
		return yzrEntityTbService.queryAllPharmacy(page, rows);
	}		
	
	//编辑药房信息
	@RequestMapping("/editPharmacy")
	public @ResponseBody Result editPharmacy(YzrPharmacy pharmacy){
		System.out.println("获取的编辑信息："+ pharmacy.getPharmacyId());
		yzrEntityTbService.editPharmacy(pharmacy);
		return new Result(true,"药房编辑成功！");
	}
	
	//根据编号查找药房
	@RequestMapping("/queryPharmacyById")
	public @ResponseBody YzrPharmacyVo queryPharmacyById(String pharmacyId){
		return yzrEntityTbService.queryPharmacyById(pharmacyId);
	}
	
	//批量删除药房
	@RequestMapping("/delPharmacy")
	public @ResponseBody Result delPharmacy(String[] list){
		yzrEntityTbService.delPharmacy(list);
		return new Result(true,"药房删除成功！");
	}
	
	//根据名称模糊查询药房
	@RequestMapping("/queryPharmacyByName")
	public @ResponseBody List<YzrPharmacyVo> queryPharmacyByName(String pharmacyName){
		return yzrEntityTbService.queryPharmacyByName(pharmacyName);
	}
	
/**************************************供应商****************************************************/
	
	//分页查询供应商
	@RequestMapping("/queryAllSupplier")
	public @ResponseBody Map<String, Object> queryAllSupplier(int page, int rows){
		return yzrEntityTbService.queryAllSupplier(page, rows);
	}
	
	//分页查询供应商
	@RequestMapping("/queryAllSupplier2")
	public @ResponseBody Map<String, Object> queryAllSupplier2(int page, int rows){
		return yzrEntityTbService.queryAllSupplier2(page, rows);
	}
	//新增供应商
	@RequestMapping("/addSupplier")
	public @ResponseBody Result addSupplier(YzrSupplier supplier){
		yzrEntityTbService.addSupplier(supplier);
		return new Result(true, "供应商添加成功！");
	}
	
	//编辑供应商
	@RequestMapping("/editSupplier")
	public @ResponseBody Result editSupplier(YzrSupplier supplier){
		yzrEntityTbService.edittSupplier(supplier);
		return new Result(true, "供应商修改成功！");
	}
	
	//根据编号查找供应商
	@RequestMapping("/querySupplierById")
	public @ResponseBody YzrSupplier querySupplierById(String supId){
		return yzrEntityTbService.querySupplierById(supId);
	}
	
	//批量删除供应商
	@RequestMapping("/delSupplier")
	public @ResponseBody Result delSupplier(String[] list){
		yzrEntityTbService.delSupplier(list);
		return new Result(true,"供应商删除成功！");
	}
	
	//根据名称模糊查询供应商
	@RequestMapping("/querySupplierByName")
	public @ResponseBody List<YzrSupplier> querySupplierByName(String pharmacyName){
		return yzrEntityTbService.querySupplierByName(pharmacyName);
	}
	
	//根据类型模糊查询供应商
	@RequestMapping("/querySupplierByKind")
	public @ResponseBody List<YzrSupplier> querySupplierByKind(String pharmacyName){
		return yzrEntityTbService.querySupplierByKind(pharmacyName);				
	}
/******************************************仓库****************************************************/
	
	//分页查询仓库信息
	@RequestMapping("/queryAllStorehouse")
	public @ResponseBody Map<String, Object> queryAllStorehouse(int page, int rows){
		return yzrEntityTbService.queryAllStorehouse(page, rows);				
	}
	
	//添加仓库
	@RequestMapping("/addStorehouse")
	public @ResponseBody Result addStorehouse(YzrStorehouse store){
		yzrEntityTbService.addStorehouse(store);
		return new Result(true, "仓库添加成功！");
	}
	
	//根据id查找仓库
	@RequestMapping("/queryStorehouseById")
	public @ResponseBody YzrStorehouseVo queryStorehouseById(String sId){
		return yzrEntityTbService.queryStorehouseById(sId);
	}
	
	//修改仓库信息
	@RequestMapping("/editStorehouse")
	public @ResponseBody Result editStorehouse(YzrStorehouse store){
		yzrEntityTbService.editStorehouse(store);
		return new Result(true, "仓库修改成功！");
	}
	
	//批量删除仓库
	@RequestMapping("/delStorehouse")
	public @ResponseBody Result delStorehouse(String[] list){
		yzrEntityTbService.delStorehouse(list);
		return new Result(true, "仓库删除成功！");
	}
	
	//根据名称模糊查询仓库
	@RequestMapping("/queryStorehouseByName")
	public @ResponseBody List<YzrStorehouseVo> queryStorehouseByName(String storeName){
		return yzrEntityTbService.queryStorehouseByName(storeName);
	}
	
/******************************************药品****************************************************/	
	//分页查询药品
	@RequestMapping("/queryAllMedicine")
	public @ResponseBody Map<String, Object> queryAllMedicine(int page, int rows){
		return yzrEntityTbService.queryAllMedicine(page, rows);
	}
	
	@RequestMapping("/queryMedicine")
	public @ResponseBody List<YzrMedicine> queryMedicine(){
		return yzrEntityTbService.queryAllMedicine2();
	}
		
	//新增药品
	@RequestMapping("/addMedicine")
	public @ResponseBody Result addMedicine(YzrMedicine medicine){
		yzrEntityTbService.addMedicine(medicine);
		return new Result(true, "药品添加成功！");
	}
		
	//编辑药品
	@RequestMapping("/editMedicine")
	public @ResponseBody Result editMedicine(YzrMedicine medicine){
		yzrEntityTbService.editMedicine(medicine);
		return new Result(true, "药品修改成功！");
	}
		
	//根据编号查找药品
	@RequestMapping("/queryMedicineById")
	public @ResponseBody YzrMedicine queryMedicineById(String medId){
		return yzrEntityTbService.queryMedicineById(medId);
	}
		
	//批量删除药品
	@RequestMapping("/delMedicine")
	public @ResponseBody Result delMedicine(String[] list){
		yzrEntityTbService.delMedicine(list);
		return new Result(true,"药品删除成功！");
	}
		
	//根据名称模糊查询药品
	@RequestMapping("/queryMedicineByName")
	public @ResponseBody List<YzrMedicine> queryMedicineByName(String medName){
		return yzrEntityTbService.queryMedicineByName(medName);
	}
		
	//根据类型模糊查询药品
	@RequestMapping("/queryMedicineByKind")
	public @ResponseBody List<YzrMedicine> queryMedicineByKind(String medName){
		return yzrEntityTbService.queryMedicineByKind(medName);				
	}
}
